package com.iammert.statusview;

import iammert.com.library.Status;
import iammert.com.library.StatusView;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

public class MainActivity extends Ability {
    Button complete;
    Button error;
    Button loading;
    Button idle;
    StatusView statusView;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_activity_main);
        statusView = (StatusView) findComponentById(ResourceTable.Id_status);
        complete = (Button) findComponentById(ResourceTable.Id_complete);
        error = (Button) findComponentById(ResourceTable.Id_error);
        loading = (Button) findComponentById(ResourceTable.Id_loading);
        idle = (Button) findComponentById(ResourceTable.Id_idle);
        complete.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                statusView.setStatus(Status.COMPLETE);
            }
        });
        error.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                statusView.setStatus(Status.ERROR);
            }
        });
        loading.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                statusView.setStatus(Status.LOADING);
            }
        });
        idle.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                statusView.setStatus(Status.IDLE);
            }
        });
    }
}
